home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 227_01 / herca.asm < prev    next >
Assembly Source File  |  1988-02-07  |  8KB  |  310 lines

  1.     page    60,132
  2. ;--------------------------------------------------------------------------
  3. ;     h e r c a . a s m
  4. ;       -----------------
  5. ;    Low-level driver for the hercules monochrome graphics card.
  6. ;
  7. ;    update history
  8. ;    --------------
  9. ;    May, 26. 1987    function "setbyte" added
  10. ;    August, 16 1987    xor functionality added
  11. ;
  12. ;    Written by     Rainer Gerhards
  13. ;            Petronellastr. 6
  14. ;            D-5112 Baesweiler
  15. ;            Phone (49) 2401 - 1601
  16. ;--------------------------------------------------------------------------
  17.  
  18.     include    dos.mac
  19.     
  20.     if1
  21.       %out    Info: Hercules graphics card driver selected.
  22.     endif
  23.  
  24. VIDBASE    equ    0b800h                ; Videoram base address
  25.  
  26. MUL90    macro    srcreg, zwsp, addreg
  27.     mov    zwsp, srcreg
  28.     shl    srcreg, 1            ; 2 *
  29.     add    srcreg, zwsp            ; 3 *
  30.     shl    srcreg, 1            ; 6 *
  31.     ifnb    <addreg>
  32.     sub    addreg, srcreg            ; correct 96 * to 90 *
  33.     else
  34.     mov    zwsp, srcreg
  35.     endif
  36.     shl    srcreg, 1            ; 12 *
  37.     shl    srcreg, 1            ; 24 *
  38.     shl    srcreg, 1            ; 48 *
  39.     shl    srcreg, 1            ; 96 *
  40.     ifnb    <addreg>
  41.     add    addreg, srcreg            ; 6 * were subtracted before
  42.     else
  43.     sub    srcreg, zwsp            ; 90 * !
  44.     endif
  45.     endm
  46. ;
  47. YOFFSET    macro    yco, zwsp, adrreg
  48.     mov    zwsp&h, yco&l            ; select bank
  49.     and    zwsp&x, 0300h
  50.     rept    5
  51.     shl    zwsp&h, 1            ; 0000 2000 4000 6000
  52.     endm
  53.     mov    adrreg, zwsp&x
  54. ;
  55.     shr    yco&x, 1            ; 90 * (y mod 4)
  56.     shr    yco&x, 1            ; y mod 4
  57.     MUL90    yco&x, zwsp&x, adrreg        ; adrreg = adrreg + 90 * yco&x
  58.     endm
  59. ;
  60. XOFFSET    macro    xco, zwsp, adrreg
  61.     ifdif    <zwsp>, <xco>
  62.     mov    zwsp, xco            ; x-coordinate
  63.     endif
  64.     rept    3
  65.     shr    zwsp, 1
  66.     endm
  67.     ifnb    <adrreg>
  68.     add    adrreg, zwsp            ; pixel byteaddress
  69.     endif
  70.     endm
  71. ;
  72. BYTEADR    macro    xco, yco, zwsp, adrreg
  73.     YOFFSET    yco, zwsp, adrreg        ; compute y-Offset
  74.     XOFFSET xco, yco&x, adrreg        ; add x-byteoffset
  75.     endm
  76.  
  77. ; ------------------- end macros ----------------------------------------
  78.  
  79.     SETX
  80.  
  81. MAX_X    equ    720            ; maximum pixel x
  82. MAX_Y    equ    348            ; maximum pixel y
  83.     PSEG
  84.  
  85.     BEGIN    clrgraph
  86. ;**
  87. ;    name        clrgraph
  88. ;
  89. ;    synopsis    clrgraph(mask);
  90. ;            int mask;    Color-mask used to clear the screen
  91. ;
  92. ;    description    Clears the graphics screen (page 1) with a
  93. ;            user-specified attribute (useally 0 or 0ffffh).
  94. ;**
  95.     ENTERF
  96.     push    es
  97.     mov    dx, VIDBASE            ; videoram-segment
  98.     mov    es, dx
  99.     xor    di, di                ; offset zero
  100.     cld                    ; count upward
  101.     mov    ax, [bp]+X            ; load attribute
  102.     mov    cx, 4000h            ; num. words in memory
  103. rep    stosw                    ; clear the page!
  104.     pop    es
  105.     LEAVEF
  106.     ENDFUNC    clrgraph            ; done!
  107.  
  108.     BEGIN    intoff
  109. ;**
  110. ;    name        intoff
  111. ;
  112. ;    synopsis    intoff();
  113. ;
  114. ;    description    This function switches all interrupts (except NMI)
  115. ;            off.
  116. ;**
  117.     cli                    ; only one instruction!
  118.     ret
  119.     ENDFUNC    intoff
  120.  
  121.     BEGIN    inton
  122. ;**
  123. ;    name        inton
  124. ;
  125. ;    synopsis    inton();
  126. ;
  127. ;    description    This function switches all interrupts on.
  128. ;**
  129.     sti                    ; only one instruction!
  130.     ret
  131.     ENDFUNC    inton
  132.  
  133.     BEGIN    setpixel
  134. ;**
  135. ;    name        setpixel
  136. ;
  137. ;    synopsis    setpixel(x, y, color);
  138. ;            int x, y;    coordinate of the pixel
  139. ;            int color;    pixel-color
  140. ;
  141. ;    description    This function sets a pixel of color "color" at
  142. ;            the specified coordinate.
  143. ;**
  144.     ENTERF
  145.     mov    si, [bp]+X            ; load x value
  146.     cmp    si, MAX_X            ; x range ok?
  147.     jae    sexit
  148.     mov    ax, [bp]+X+2            ; load y value
  149.     cmp    ax, MAX_Y            ; y range ok?
  150.     jae    sexit
  151.     mov    bx, [bp]+x+4            ; load color
  152. ;
  153.     BYTEADR    si, a, c, di             ; byteoffset -> di
  154. ;
  155.     mov    ax, bx                ; color,
  156.     mov    ah, 01h                ; use only least significant
  157.     and    al, ah                ; bit!
  158.     mov    cx, si                ; x-coordinate
  159.     and    cl, 7                ; 7 - last 3 bit
  160.     xor    cl, 7                ; = Bitoffset
  161.     shl    ax, cl                ; shift color and mask
  162. ;
  163.     not    ah                ; Mask pixel off
  164.     mov    cx, VIDBASE            ; load base adr
  165.     mov    si, es                ; save ES
  166.     mov    es, cx
  167.     mov    cl, es:[di]            ; read pixel
  168.     cmp    bx, -1                ; xor?
  169.     jne    wrtpx
  170.     xor    cl, al
  171.     jmp    short rwrt            ; rewrite to display
  172. wrtpx:    and    cl, ah                  ; clear old color
  173.     or    cl, al                ; set new color
  174. rwrt:    mov    es: [di], cl            ; back to display memory! 
  175.     mov    es, si                ; restore saved ES
  176. sexit:    LEAVEF                    ; done!
  177.     ENDFUNC    setpixel
  178.  
  179.     BEGIN    getpixel
  180. ;**
  181. ;    name        getpixel
  182. ;
  183. ;    synopsis    color = getpixel(x, y);
  184. ;            int x, y;    coordinate of the pixel
  185. ;            int color;    returned color of that pixel
  186. ;
  187. ;    description    This function reads ("gets") the color of a
  188. ;            specified pixel.
  189. ;**
  190.     ENTERF
  191.     mov    si, [bp]+X            ; load x coordinate
  192.     cmp    si, MAX_X            ; x range ok?
  193.     jae    gexit
  194.     mov    ax, [bp]+X+2            ; load y coordinate
  195.     cmp    ax, MAX_Y            ; y range ok?
  196.     jae    gexit
  197. ;
  198.     BYTEADR    si, a, c, di             ; byteoffset -> di
  199. ;
  200.     mov    ax, VIDBASE            ; load segment graphic page 1
  201.     mov    cx, es                ; save ES
  202.     mov    es, ax
  203.     mov    bl, es:[di]            ; this byte contains the pixel
  204.     mov    es, cx                ; restore saved ES
  205.     or    bl, bl                ; any pixel set?
  206.     jz    goret                ; no, done!
  207.     mov    cx, si                ; x-coordinate
  208.     and    cl, 7                ; 7 - last 3 bit
  209.     xor    cl, 7                ; = shiftcount
  210.     shr    bl, cl                ; shift to position 0
  211.     and    bl, 01                ; last bit only
  212. ;
  213. goret:    mov    ax, bx                ; function result must 
  214. gexit:    LEAVEF                    ; be in ax
  215.     ENDFUNC    getpixel
  216.  
  217.     BEGIN    setbyte
  218. ;**
  219. ;    name        setbyte
  220. ;
  221. ;    synopsis    setbyte(x, y, gr_byte);
  222. ;            int x;        x-coordinate of the byte, only
  223. ;                    valid if multiple of 8
  224. ;            int y;        y-coordinate of the byte, may have
  225. ;                    any valid value
  226. ;            int gr_byte;    byte of graphics to set
  227. ;                    if (gr_byte >> 8) == 0xff then
  228. ;                    xor vidmem with gr_byte & 0xff!
  229. ;
  230. ;    description    This function puts the graphics pattern contained
  231. ;            in gr_byte into the adapter memory. Gr_byte must
  232. ;            be a multiple of 8, all other values are invalid
  233. ;            and will be rounded. Gr_byte is defined as con-
  234. ;            secutive 8 pixles on the x-axis.
  235. ;
  236. ;    warning        This function is only available with the hercules
  237. ;            driver. It schould be treated as available internal
  238. ;            to the grphics library only. If you have to use it,
  239. ;            use conditional compilation, too. This function is
  240. ;            only available when #ifdef HERCGRAF == true!
  241. ;**
  242.     ENTERF
  243.     mov    si, [bp]+X            ; load x value
  244.     cmp    si, MAX_X            ; x range ok?
  245.     jae    bexit
  246.     mov    ax, [bp]+X+2            ; load y value
  247.     cmp    ax, MAX_Y            ; y range ok?
  248.     jae    bexit
  249. ;
  250. ;    everything ok - can perform my job.
  251. ;
  252.     mov    bx, [bp]+X+4            ; load graphics information
  253.     BYTEADR    si, a, c, di             ; byteoffset -> di
  254.     mov    cx, VIDBASE            ; load base adr of page 1
  255.     mov    si, es                ; save ES
  256.     mov    es, cx
  257.     cmp    bh, 0ffh            ; xor byte?
  258.     jne    endbyt
  259.     xor    es: [di], bl
  260.     jmp    short endsb
  261. endbyt:    mov    es: [di], bl            ; set screen memory
  262. endsb:    mov    es, si                ; restore saved ES
  263. bexit:    LEAVEF                    ; done!
  264.     ENDFUNC    setbyte
  265.  
  266.     BEGIN    getbyte
  267. ;**
  268. ;    name        getbyte
  269. ;
  270. ;    synopsis    gr_byte = getbyte(x, y);
  271. ;            int x;        x-coordinate of the byte, only
  272. ;                    valid if multiple of 8
  273. ;            int y;        y-coordinate of the byte, may have
  274. ;                    any valid value
  275. ;            int gr_byte;    byte of graphics to read
  276. ;
  277. ;    description    This function reads the whole byte of graphics at
  278. ;            the specified position. That means, it read 8
  279. ;            consecutive pixel.
  280. ;
  281. ;    warning        This function is only available with the hercules
  282. ;            driver. It schould be treated as available internal
  283. ;            to the grphics library only. If you have to use it,
  284. ;            use conditional compilation, too. This function is
  285. ;            only available when #ifdef HERCGRAF == true!
  286. ;
  287. ;    NOT FULLY TESTED!
  288. ;
  289. ;**
  290.     ENTERF
  291.     mov    si, [bp]+X            ; load x value
  292.     cmp    si, MAX_X            ; x range ok?
  293.     jae    gbexit
  294.     mov    ax, [bp]+X+2            ; load y value
  295.     cmp    ax, MAX_Y            ; y range ok?
  296.     jae    gbexit
  297. ;
  298.     BYTEADR    si, a, c, di             ; byteoffset -> di
  299.     mov    cx, VIDBASE            ; load base adr of page 1
  300.     mov    si, es                ; save ES
  301.     mov    es, cx
  302.     mov    al, es: [di]            ; get 8 pixel
  303.     and    ax, 0ffh            ; mask off high byte
  304.     mov    es, si                ; restore saved ES
  305. gbexit:    LEAVEF                    ; done!
  306.     ENDFUNC    getbyte
  307.     ENDPS
  308.     end
  309.     END
  310.